%start START

%token CLASS FUNCTION CONSTRUCTOR MAIN RETURN ARRAY INT IF ELSE WHILE PRINT NEW END INTLITERAL ID ASSIGN DELIMETER SEMICOLON LESS COLON POINT DIV LESSOREQUAL AND OR COMMA NO ADD SUB MUL EQUAL LFIGUREBRACKET RFIGUREBRACKET LROUNDBRACKET RROUNDBRACKET

%%

START : Program END { printf("Correct\n"); exit(0); };

Program : MainBlock ClassDecls;

MainBlock : MAIN LFIGUREBRACKET VarDecls DELIMETER Stmts RFIGUREBRACKET;

ClassDecls : ClassDecl ClassDecls
            | ;

ClassDecl : CLASS ID LFIGUREBRACKET VarDecls DELIMETER CONSTRUCTOR LROUNDBRACKET FormalList RROUNDBRACKET LFIGUREBRACKET Stmts RFIGUREBRACKET MethodDecls RFIGUREBRACKET;

VarDecls : VarDecl VarDecls
          | ;

VarDecl : Type ID SEMICOLON;

MethodDecls : MethodDecl MethodDecls
             | ;

MethodDecl : FUNCTION ID LROUNDBRACKET FormalList RROUNDBRACKET COLON Type LFIGUREBRACKET VarDecls DELIMETER Stmts RETURN Exp SEMICOLON RFIGUREBRACKET;

FormalList : Type ID FormalRest
            | ;

FormalRest : COMMA Type ID FormalRest
            | ;

Type : StandardType
      | ID;

StandardType : ARRAY
              | INT;

Stmts : Stmt Stmts
       | ;

Stmt : LFIGUREBRACKET Stmts RFIGUREBRACKET
      | IF LROUNDBRACKET LogicExp RROUNDBRACKET Stmt ELSE Stmt
      | WHILE LROUNDBRACKET LogicExp RROUNDBRACKET Stmt
      | PRINT LROUNDBRACKET Exp RROUNDBRACKET SEMICOLON
      | ID ASSIGN Exp SEMICOLON
      | ID ASSIGN NEW ID LROUNDBRACKET ExpList RROUNDBRACKET SEMICOLON
      | ID ASSIGN NEW StandardType LROUNDBRACKET INTLITERAL RROUNDBRACKET SEMICOLON;

LogicExp : ID LogicExp1
          | NO LogicExp
          | LROUNDBRACKET LogicExp RROUNDBRACKET LogicExp1;

LogicExp1 : LogicOp LogicExp
           | ;

LogicOp : EQUAL
         | LESS
         | AND
         | OR
         | LESSOREQUAL;

Exp : Exp1 Exp2
     | SUB Exp1 Exp2;

Exp2 : Op Exp1 Exp2
      | ;

Exp1 :  ID POINT ID LROUNDBRACKET ExpList RROUNDBRACKET
      | ID
      | INTLITERAL
      | LROUNDBRACKET Exp RROUNDBRACKET;

Op : ADD
    | SUB
    | MUL
    | DIV;

ExpList : Exp ExpRest
         | ;

ExpRest : COMMA Exp ExpRest
         | ;

%%